<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<script>
	function rechargeRule_check(rechargeMoney,firstGiveMoney,givePoint,frequency,everyGiveMoney,giveCount){
		 if(!rechargeMoney||!firstGiveMoney||!givePoint||!frequency||!everyGiveMoney||!giveCount){
		 	alert("都为必填项，请输入");
		 	return false;
		 }
		return true;
	}
	
	function rechargeRule_deltr(id){
		if(!confirm("您确定要删除该充值规则吗？"))return;
		$.ajax({cache:false, 
		url:"<%=path%>/ajax/deleteRechargeRule.do?id="+id, 
		type:"post", 
		dataType:"json", 
		success:handProcessResult2});
	}
	
	function rechargeRule_ajaxsubmit(){
		var rechargeMoney = $("input[name='rechargeRuleVO.rechargeMoney']").val();
		var firstGiveMoney = $("input[name='rechargeRuleVO.firstGiveMoney']").val();
		var givePoint = $("input[name='rechargeRuleVO.givePoint']").val();
		var frequency = $("input[name='rechargeRuleVO.frequency']").val();
		var everyGiveMoney = $("input[name='rechargeRuleVO.everyGiveMoney']").val();
		var giveCount = $("input[name='rechargeRuleVO.giveCount']").val();
		if(rechargeRule_check(rechargeMoney,firstGiveMoney,givePoint,frequency,everyGiveMoney,giveCount)){
			$.ajax({cache:false, 
			url:"<%=path%>/ajax/saveRechargeRule.do?cardEntityId=${rechargeRuleVO.cardEntityId}"
			+"&rechargeMoney="+rechargeMoney
			+"&firstGiveMoney="+firstGiveMoney
			+"&givePoint="+givePoint
			+"&frequency="+frequency
			+"&everyGiveMoney="+everyGiveMoney
			+"&giveCount="+giveCount, 
			type:"post", 
			dataType:"json", 
			success:function(json){handProcessResult2(json.result);}});
		}
	}
	
	function handProcessResult2(json){
		DWZ.ajaxDone(json);
		if (json.statusCode == DWZ.statusCode.ok){
			reloadRechargeRulePage();
		}
	}
	
	function reloadRechargeRulePage(){
		return divSearch($("#rechargeRule_form"), "cardEntityEdit_rechargeRule");
	}
</script>
	<head>
		<title>初始计次</title>
	</head>
	<body>
<div id="cardEntityEdit_rechargeRule">
	<form id="pagerForm" method="post" action="<%=path%>/rechargeRule/listRechargeRule.action?cardEntityId=${rechargeRuleVO.cardEntityId}">
		<input type="hidden" name="pageRequest" value="1" />
		<input type="hidden" name="pageNum" value="${paginator.pageIndex}" />
		<input type="hidden" name="numPerPage" value="${paginator.pageSize}" />
	</form>
		<div class="pageContent">
		<c:choose>
		<c:when test="${rechargeRuleVO.cardEntityId!=null && rechargeRuleVO.cardEntityId!=''}">
			<form method="post" action="" class="pageForm required-validate">
				<div class="pageFormContent">
					<input type="hidden" name="rechargeRuleVO.cardEntityId" value="<s:property value="rechargeRuleVO.cardEntityId"/>"/>
					<p>
						<label>
							充值金额：
						</label>
						<input name="rechargeRuleVO.rechargeMoney" class="required number" type="text"/>
					</p>
					<p>
						<label>
							首次赠送：
						</label>
						<input name="rechargeRuleVO.firstGiveMoney" class="required number" type="text"/>
					</p>
					<p>
						<label>
							赠送积分：
						</label>
						<input name="rechargeRuleVO.givePoint" class="required digits" type="text"/>
					</p>
					<p>
						<label>
							反赠间隔：
						</label>
						<input name="rechargeRuleVO.frequency" class="required digits" type="text"/>天
					</p>
					<p>
						<label>
							反赠金额：
						</label>
						<input name="rechargeRuleVO.everyGiveMoney" class="required number" type="text"/>
					</p>
					<p>
						<label>
							反赠次数：
						</label>
						<input name="rechargeRuleVO.giveCount" class="required number" type="text"/>
					</p>
				</div>
				<div class="formBar">
					<ul>
						<li>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="button" onclick="rechargeRule_ajaxsubmit();">
										增加
									</button>
								</div>
							</div>
						</li>
					</ul>
				</div>
				<table class="table" width="100%" layoutH="232">
					<thead>
						<tr>
							<th align="center">
								充值规则
							</th>
							<th width="70">
								操作
							</th>
						</tr>
					</thead>
					<tbody id="tab">
						
						<s:iterator value="rechargeRuleList" id="rechargeRule" status="st">
							<tr class="" align="center" id="<s:property value="id" />">
								<td>
									充值<s:property value="rechargeMoney" />元，首次额外赠送<s:property value="firstGiveMoney" />元和
									<s:property value="givePoint" />积分，后续每隔<s:property value="frequency" />天，
									每次赠送<s:property value="everyGiveMoney" />元，共反赠<s:property value="giveCount" />次。
								</td>
								<td>
									<a class="btnDel" onclick="rechargeRule_deltr('<s:property value="id"/>');">删除</a>
								</td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</form>
			<div class="panelBar">
		<div class="pages">
				<span>显示</span>
				<select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value},'cardEntityEdit_rechargeRule')">
					<option value="15" <c:if test="${paginator.pageSize==15}">selected='selected'</c:if> >15</option>
					<option value="30" <c:if test="${paginator.pageSize==30}">selected='selected'</c:if> >30</option>
					<option value="50" <c:if test="${paginator.pageSize==50}">selected='selected'</c:if> >50</option>
					<option value="100" <c:if test="${paginator.pageSize==100}">selected='selected'</c:if> >100</option>
					<option value="200" <c:if test="${paginator.pageSize==200}">selected='selected'</c:if> >200</option>
				</select>
				<span>条，共${paginator.totalCount}条</span>
			</div>
			<div class="pagination" rel="cardEntityEdit_rechargeRule" totalCount="${paginator.totalCount}" 
				numPerPage="${paginator.pageSize}" pageNumShown="10" currentPage="${paginator.pageIndex}"></div>
	</div>
		</c:when>
			<c:otherwise>
				<p><span style="color:red">请先创建会员卡</span></p>
			</c:otherwise>
		</c:choose>
		</div>
		<div>
		<form id="rechargeRule_form" method="post" rel="pagerForm" action="<%=path%>/rechargeRule/listRechargeRule.action?cardEntityId=${rechargeRuleVO.cardEntityId}"></form>
		</div>
</div>
	</body>
</html>